// pages/notice/testresult/testresult.js结业报告
const app=getApp();
let tool = require('../../../utils/tool.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imageurl: 'https://yxpmaterial.oss-cn-beijing.aliyuncs.com/',
    info:{}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.data.id = options.id;
    this.getdata()
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getdata:function(){
    let that=this;
    let paramArr = {
     access_token: app.globalData.studentInfo.access_token,
     id: this.data.id
    }
    let rs = tool.getSign(paramArr, app.globalData.key); //返回 bodyParam heaer sign
    let sign = rs.sign;
    let apiUrl = app.globalData.apiURL + "message/completereport?sign=" + sign;
    let infoPro = new Promise(
      function (resolve, reject) {
        wx.request({
          url: apiUrl,
          header: rs.header,
          data: rs.bodyParam,
          method: 'post',
          success(rs) {
            if (rs.data.code == 1) {
              let date = new Date;
              let year = date.getFullYear()
              let month = date.getMonth() + 1
              let day = date.getDate()
              that.setData({
                info: rs.data.data,
                dd: year + "年" + month + "月" + day + "日"
              })
            } else if (rs.data.code == 10001) {
              wx.redirectTo({
                url: '/pages/login/login',
              })
            }
          }
        })
      }
    );
   
  }
})